<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>大小图切换</title>

    <style>
      #banner {
        user-select: none;
      }
      #banner > img {
        width: 500px;
      }
      #banner > div > img {
        width: 100px;
        /* transparent: 透明 */
        border: 3px solid transparent;
      }

      #banner > div > img.cur {
        border-color: blue;
      }
    </style>
  </head>
  <body>
    <div id="banner">
      <img src="./images/1-l.jpg" alt="" />
      <div>
        <img data-big="1-l" class="cur" src="./images/1.jpg" alt="" />
        <img data-big="2-l" src="./images/2.jpg" alt="" />
        <img data-big="3-l" src="./images/3.jpg" alt="" />
        <img data-big="4-l" src="./images/4.jpg" alt="" />
      </div>
    </div>

    <script>
      // 1. 查询到所有的小图, 遍历添加鼠标悬浮事件 onmouseover
      const small_imgs = document.querySelectorAll('#banner>div>img')
      small_imgs.forEach(value => {
        value.onmouseover = function () {
          // 2. 触发时, 找到 cur 样式的元素, 去掉 cur 样式
          const cur = document.querySelector('#banner .cur')
          cur.classList.remove('cur')
          // 3. 为当前项添加 cur 样式
          this.classList.add('cur')

          const big = this.dataset.big

          const big_img = document.querySelector('#banner>img')
          big_img.src = `./images/${big}.jpg`
        }
      })
    </script>
  </body>
</html>
